export class AnswerFlowService {

    constructor(parent) {
        this.parent = parent;
    }

    showAnswer() {
        $.each(this.parent.questionServiceList, function (index, item) {
            item.service.showAnswer();
        });
    }

    onTimeOver(timespend) {
        this.parent.logger.debug("时间结束,开始收集答案");
        if (this.parent.embedApplication('pptshell')) {
            //如果是PPTShell
            this.parent._forceStopAnswer();
        } else if (this.parent.Environment.isApp) {
            //不再触发提答案的流程, 而是设置标志位
            this.parent.isTimeOver = true;
        }
    }

    setTimerService(timeService) {
        this.parent.timerService = timeService;
        //this.parent._allReady();
    }
}

export class AnswerControllerService {
    constructor(parent) {
        this.parent = parent;
    }

    @Midway.FixPropertyConfig({enumerable: true})
    getInterfaceMethods() {
        return [{
            name: "IInteractionQuestion",
            methods: ["getQuestionInfo", "showAnswer", "getResult", "lockQuestion",
                "unlockQuestion", "finishQuestion", "resetQuestion", "showResultHint"]
        }, {
            name: "ISubmitButton",
            methods: ["setButtonState", "getButtonState", "setVisible"]
        }, {
            name: "IAnswerIntercept",
            methods: ["getInterceptId", "beforeSendAnswer", "afterSendAnswer"]
        }]
    }

    @Midway.FixPropertyConfig({enumerable: true})
    afterPresenterRun(interfaceName, metaInfo, service) {
        if (interfaceName == 'IInteractionQuestion') {
            this.parent.questionServiceList.push(service);
        } else if (interfaceName == 'ISubmitButton' && this.parent.submitButtonService == null) {
            //确保当前的AFC中的按钮变量不会被其他的请求修改
            this.parent.submitButtonService = service;
        } else if (interfaceName == 'IAnswerIntercept') {
            this.parent.answerIntercept.push(service);
        }
    }
}